//
//  ViewController.m
//  18-SQLite
//
//  Created by Snow on 16/8/8.
//  Copyright © 2016年 Snow. All rights reserved.
//

#import "ViewController.h"
#import "SQLiteDataBaseManager.h"
#import "Student.h"
@interface ViewController ()

@property (nonatomic, strong) SQLiteDataBaseManager *dataBaseManager;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    //SQLite
    //注意: 使用SQLite需要引入 libsqlite3.0.tdb
    //libsqlite3.0.tbd 是  libsqlite3.tbd 的替身文件, 防止用户误删
    _dataBaseManager = [SQLiteDataBaseManager sharedManager];
}
- (IBAction)openSQlite:(id)sender {
    [_dataBaseManager openSQLite3];
}
- (IBAction)closeSQLite:(id)sender {
    [_dataBaseManager closeSQLite3];
}
- (IBAction)createTable:(id)sender {
    [_dataBaseManager createTable];
}
- (IBAction)insertSTU:(id)sender {
    Student *stu = [[Student alloc] init];
    stu.stu_id = 38;
    stu.stu_name = @"XX";
    [_dataBaseManager insertStu:[Student new]];
}
- (IBAction)deleteStu:(id)sender {
//    Student *stu = [[Student alloc] init];
//    stu.stu_id = 38;
//    stu.stu_name = @"XX";
//    [_dataBaseManager deleteStu:[Student new]];
    [_dataBaseManager deleteAll];
}
- (IBAction)updateStu:(id)sender {
    
    [_dataBaseManager updateOldName:@"ggg" newName:@"王道林"];
}
- (IBAction)searchStu:(id)sender {
    NSArray *ARR = [_dataBaseManager searchAll];
    NSLog(@"%@", ARR);
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
